﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MusicService
{
    public partial class MusicService:ISongAuthorService
    {
        public bool addSongAuthor(string authorID, string songID)
        {
            bool flag = false;
            SongAuthor songAuthor = new SongAuthor(); 
            try
            {
                songAuthor.AuthorID = authorID;
                songAuthor.SongID = songID;
                dc.SongAuthors.InsertOnSubmit(songAuthor);
                dc.SubmitChanges();
                flag = true;
            }
            catch (Exception)
            {

            }
            return flag;
        }

        public bool removeSongAuthor(string authorID, string songID)
        {
            bool flag = false;
            try
            {
                SongAuthor songAuthor = dc.SongAuthors.Single(tmp => tmp.AuthorID.Equals(authorID) &&
                    tmp.SongID.Equals(songID));
                if (songAuthor != null)
                {
                    dc.SongAuthors.DeleteOnSubmit(songAuthor);
                    dc.SubmitChanges();
                    flag = true;
                }
            }
            catch (Exception)
            {

            }
            return flag;
        }

        public bool updateSongAuthor(string authorID, string songID)
        {
            bool flag = false;
            try
            {
                SongAuthor songAuthor = dc.SongAuthors.Single(tmp => tmp.AuthorID.Equals(authorID) &&
                    tmp.SongID.Equals(songID));
                if (songAuthor != null)
                {
                    songAuthor.AuthorID = authorID;
                    songAuthor.SongID = songID;
                    dc.SubmitChanges();
                    flag = true;
                }
            }
            catch (Exception)
            {

            }
            return flag;
        }
        public List<SongAuthor> getAllSongAuthor()
        {
            var list = from sa in dc.SongAuthors select sa;
            return list.ToList();
        }
        public SongAuthor getSongAuthorByID(string authorID, string songID)
        {
            SongAuthor songAuthor = dc.SongAuthors.Single(tmp => tmp.AuthorID.Equals(authorID) &&
                tmp.SongID.Equals(songID));
            return songAuthor;
        }
    }
}